package com.zhicheng.controller;

import com.zhicheng.pojo.AddressBook;
import com.zhicheng.pojo.Good;
import com.zhicheng.pojo.dto.GoodDTO;
import com.zhicheng.pojo.result.PageResult;
import com.zhicheng.pojo.result.Result;
import com.zhicheng.pojo.vo.GoodVO;
import com.zhicheng.service.GoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Api(tags = "商品相关接口")
public class GoodController {

    @Autowired
    private GoodService goodService;

    @GetMapping("/goods")
    @ApiOperation("根据id查询商品信息")
    public Result<GoodVO> getGoodsById(Long id) {
        GoodVO goods = goodService.getGoodsById(id);
        return Result.success(goods);
    }

    @GetMapping("/goods/hot")
    @ApiOperation("根据商品点赞量排序查询商品信息")
    public Result<List<GoodVO>> getHotGoodsByLikeCount(Long id, Long limit) {
        List<GoodVO> goods = goodService.getHotGoodsByLikeCount(id, limit);
        return Result.success(goods);
    }

    @GetMapping("/member/goods")
    @ApiOperation("根据用户id分页查询商品")
    public Result<PageResult<Good>> list(int page, int pageSize,
                                                @RequestParam(required = false) Integer categoryId,
                                                @RequestParam(required = false) Integer status) {
        PageResult<Good> pageResult = goodService.list(page, pageSize,categoryId,status);
        return Result.success(pageResult);
    }

    @PostMapping("/goods/add")
    @ApiOperation("用户添加商品")
    public Result add(@RequestBody GoodDTO goodDTO) {
        goodService.add(goodDTO);
        return Result.success();
    }

    @PutMapping("/goods/update")
    @ApiOperation("修改用户商品信息")
    private Result update(@RequestBody GoodDTO goodDTO) {
        goodService.updateGoods(goodDTO);
        return Result.success();
    }

    @DeleteMapping("/goods/delete")
    @ApiOperation("删除用户收货地址信息")
    private Result delete(Long id) {
        goodService.deleteGoods(id);
        return Result.success();
    }

}
